function popupPricing() {
	new Interactive.Popups.Popup('/getPopup?page=pricing', 'pricePopup', true, 660, 500, function(){
		var credits = getCheckedValue(document.getElementById('pricePopup').contentWindow.document.getElementsByName("package"));
		var form = document.getElementById("payPalForm");
		document.getElementById("amount").value = credits;
		if(document.getElementById("returnUrl") != null) {
			var returnPath = window.location.href;
			if(document.getElementById("pageContextExt") != null) {
				returnPath += document.getElementById("pageContextExt").value;
			}
			document.getElementById("returnUrl").value = returnPath;
		} 
		form.submit();
	});
}

var searchPopup;
function popupSearchFaq() {
	searchPopup = new Interactive.Popups.Popup('/getPopup?page=activeSearchFAQs', 'activeSearchFaq', true, 870, 900, null);
}


function popupConfirmBuy(credits, amount) {
	credits = eval(credits);
	amount = eval(amount);

	if (credits < amount) {
		alert("You do not have enough credits to get the contact details and the resume for these applicants, please click 'Buy Credits'.");
		return;
	}
	processSmartTableSelectedRows("myAsnResponseForm", "myAsnBriefSmartTable", doPopupConfirmBuy);
}

function doPopupConfirmBuy(selectedJobs) {
	if (selectedJobs == "") {
		alert("No profiles were selected");
		return;
	}
	new Interactive.Popups.Popup('/getPopup?page=confirmBuy&asnjobs=' + selectedJobs, 'confirmBuy', true, 670, 500, function(){
			buyProfiles(selectedJobs);	
	});
}

var selectedSearch = null;

function selectSearch(id, name, status) {
	this.id = id;
	this.name = name;
	this.status = status;
}

function submitForm(event) {
	var form = document.forms["myAsnForm"];
	form._eventId.value = event;
	form.submit();
}

function submitAsnItem(jobId) {
	var form = document.forms["myAsnForm"];
	form.selectedJobId.value = jobId;
	submitForm("viewBrief");
}

function closeSelectedSearch() {
	if (selectedSearch == null ) {
		var closeSearchAlert = new Interactive.Popups.Alert(500, 150, '<b>Please select search</b>', null);
	} else {
		if (selectedSearch.status != "Activated") {
			var closeSearchAlert = new Interactive.Popups.Alert(500, 150, '<b>You can only close searches with a status of "<i>Activated</i>"</b>', null);
		} else {
		    var closeSearchConfirm = new Interactive.Popups.Confirm(500, 200, '<font size="6" color="#AABFDC">Close Search?</font><br/><br/> You are about to close search "<i>'+ selectedSearch.name +'</i>".  This job will be removed from the job board, and all applicants that are not in the Offer stage will be notified that the position is no longer available.',
		 	[function(){processSearchClosing(selectedSearch.id)}, null]);
	 	}
 	}
}

function processSearchClosing(searchId) {
	sendJsonRequest("map.json", "searchId=" + searchId, cbSearchClosing, "closeSearch", "MyAsnHandler");
}

function cbSearchClosing(ds) {
	var result = ds.getData()[0].json;
	//alert(result);
	refreshSmartTable('myAsnForm','myAsnSmartTable');
	selectedSearch = null;
	refreshSmartTable('myAsnForm','myAsnSummaryTable');
}

function UnSubmitSearch() {
	if (selectedSearch == null) {
		var unSubmitSearchAlert = new Interactive.Popups.Alert(500, 150, '<b>Please select search</b>', null);
	} else {
		if( selectedSearch.status != "Submitted") {
			var unSubmitSearchAlert = new Interactive.Popups.Alert(500, 150, '<b>You can only un-submit searches with a status of "<i>Submitted</i>"</b>', null);
		} else {
		    var closeUnSubmitConfirm = new Interactive.Popups.Confirm(500, 200, '<font size="6" color="#AABFDC">Cancel Submission?</font><br/><br/> You are about to Un-Submit search "<i>'+ selectedSearch.name +'</i>", and change the status to \'Pending Submission\'.  You can re-submit your search anytime by going back and pressing the submit button in the search page.',
		 	[function(){processSearchUnSubmitting(selectedSearch.id)}, null]);
	 	}
 	}
}

function processSearchUnSubmitting(searchId) {
	sendJsonRequest("map.json", "searchId=" + searchId, cbSearchUnSubmitting, "unSubmitSearch", "MyAsnHandler");
}

function cbSearchUnSubmitting(ds) {
	var result = ds.getData()[0].json;
	refreshSmartTable('myAsnForm','myAsnSmartTable');
	selectedSearch = null;
	refreshSmartTable('myAsnForm','myAsnSummaryTable');
}

function buyProfiles(selectedAsnJobs) {
	sendJsonRequest("map.json", "selectedAsnJobs=" + selectedAsnJobs, cbBuyProfiles, "buyProfile", "MyAsnHandler", null, true);
}

function cbBuyProfiles(ds) {
	alert(ds.getData()[0].json);
	var loc = document.location; 
	if (loc.pathname.indexOf("showprofile") >= 0) {
		setTimeout("location.reload(true);",500);
	} else {
		refreshSmartTable('myAsnResponseForm','myAsnBriefSmartTable');
	}
}
